// ignore_for_file: constant_identifier_names

import 'dart:collection';
import 'dart:io';
import 'dart:math';
import 'package:common_utils/common_utils.dart';
import 'package:eq/eq.dart';
import 'package:eq/src/statement.dart';

List<int> code = List.empty(growable: true);
int codeLen = 0; //当前模块代码总长度
int currentposL = 0; //当前分析列的位置
int currentposH = 1; //当前分析行的位置
int currentpos = 0; //当前分析的位置
int currentChar = 0; //当前分析的字符
bool exitIso = false;

enum ExpressionType {
  BOOLEAN_EXPRESSION,
  INT_EXPRESSION,
  DOUBLE_EXPRESSION,
  STRING_EXPRESSION,
  REGEXP_EXPRESSION,
  IDENTIFIER_EXPRESSION,
  GLOBAL_EXPRESSION,
  COMPLEX_EXPRESSION,
  COMMA_EXPRESSION,
  ASSIGN_EXPRESSION,
  ADD_EXPRESSION,
  SUB_EXPRESSION,
  MUL_EXPRESSION,
  DIV_EXPRESSION,
  MOD_EXPRESSION,
  DOT_DIV_EXPRESSION,
  DOT_MUL_EXPRESSION,
  BIT_AND_EXPRESSION,
  BIT_OR_EXPRESSION,
  BIT_XOR_EXPRESSION,
  EQ_EXPRESSION,
  NE_EXPRESSION,
  GT_EXPRESSION,
  GE_EXPRESSION,
  LT_EXPRESSION,
  LE_EXPRESSION,
  LOGICAL_AND_EXPRESSION,
  LOGICAL_OR_EXPRESSION,
  MINUS_EXPRESSION,
  BIT_NOT_EXPRESSION,
  LOGICAL_NOT_EXPRESSION,
  FUNCTION_CALL_EXPRESSION,
  NULL_EXPRESSION,
  ARRAY_EXPRESSION,
  INDEX_EXPRESSION,
  INCREMENT_EXPRESSION,
  DECREMENT_EXPRESSION,
  MODULE_CALL_EXPRESSION,
  Invalid_EXPRESSION,
  EXPRESSION_TYPE_COUNT_PLUS_1
}

enum AssignmentOperator {
  NORMAL_ASSIGN,
  ADD_ASSIGN,
  SUB_ASSIGN,
  MUL_ASSIGN,
  DIV_ASSIGN,
  MOD_ASSIGN,
  BIT_XOR_ASSIGN,
  BIT_AND_ASSIGN,
  BIT_OR_ASSIGN,
}

class AssignExpression {
  AssignmentOperator operator;
  late Expression left;
  late Expression operand;
  AssignExpression(this.operator);
}

class IncrementOrDecrement {
  final Expression operand;
  const IncrementOrDecrement(this.operand);
}

class CommaExpression {
  final Expression left;
  final Expression right;

  const CommaExpression(this.left, this.right);
}

class BinaryExpression {
  final Expression left;
  final Expression right;

  const BinaryExpression(this.left, this.right);
}

class ArgumentList extends LinkedListEntry<ArgumentList> {
  final Expression expression;
  ArgumentList(this.expression);
}

class FunctionCallExpression {
  final Expression function;
  late LinkedList<ArgumentList> argument;
  FunctionCallExpression(this.function);
}

class IndexExpression {
  final Expression array;
  final Expression index;

  const IndexExpression(this.array, this.index);
}

class Expression extends LinkedListEntry<Expression> {
  ExpressionType type;
  late bool boolvalue;
  int? intvalue;
  double? doublevalue;
  late String stringvalue;
  late String regexpvalue;
  late String identifier;
  String? module;
  Array array = Array();
  late Expression minusExpression;
  late AssignExpression assignExpression;
  late IncrementOrDecrement incDec;
  late CommaExpression comma;
  late BinaryExpression binaryExpression;
  late FunctionCallExpression functionCallExpression;
  late IndexExpression indexExpression;
  int? rowNum;
  int? colNum;
  Expression(this.type);
  @override
  String toString() {
    return "ExpressionType:$ExpressionType ";
  }
}

void exitApp(String msg, int code) {
  print('$code:$msg');
  if (exitIso) {
    exitScript(msg, code);
  } else {
    exit(code);
  }
}

///变量类，定义后变量名不可更改，值可以
class Variable extends LinkedListEntry<Variable> {
  final String name;

  ///是否常量
  final bool isFixed;
  Value value;
  Variable(this.name, this.value, {this.isFixed = false});
  @override
  String toString() {
    return " name:$name isFixed:$isFixed value:$value";
  }
}

//数组类
class Array {
  late List<LinkedList<Expression>> array;
  Array() {
    array = List.empty(growable: true);
  }
}

class Block {
  late final LinkedList<Statement> statementList;
  Block();
}

class Parameter extends LinkedListEntry<Parameter> {
  final String name;
  Parameter(this.name);
}

///编译器支持的基本数据类型
enum ValueType {
  BOOLEAN_VALUE,
  INT_VALUE,
  DOUBLE_VALUE,
  STRING_VALUE,
  REGEXP_VALUE,
  COMPLEX_VALUE,
  ARRAY_VALUE,
  NULL_VALUE,
  FUNCTION_VALUE,
  UNDEFINED_VALUE,
  NATIVE_POINTER_VALUE,
}

class Value extends LinkedListEntry<Value> {
  final ValueType type;
  final dynamic value;
  String module; //模块别名 给模块调用表达式使用,即类型为FUNCTION_VALUE
  String? path; //模块路径,模块唯一区分值
  Value(this.type, this.value, {this.module = ''});

  @override
  String toString() {
    //return " type:" + type.toString() + " value:" + value.toString();

    if (type == ValueType.FUNCTION_VALUE) {
      return "$module.$value";
    } else if (type == ValueType.NATIVE_POINTER_VALUE) {
      ///类型为此时暂存native类型字符串,value被用来存储本地指针
      return module;
    }
    // else if (type == ValueType.STRING_VALUE) {
    //   return "\"$value\"";
    // } else if (type == ValueType.REGEXP_VALUE) {
    //   return "'$value'";
    // }
    else {
      return value.toString();
    }
  }

  @override
  bool operator ==(Object other) {
    if (other is Value) {
      if ((type == other.type) && (value == other.value)) {
        return true;
      }
    }
    return false;
  }

  @override
  int get hashCode => Object.hash(type, value);
}

///内置函数定义
typedef NativeFunctionProc = Value Function(List<Value> args);

///函数定义类
class FunctionDefinition extends LinkedListEntry<FunctionDefinition> {
  final String name;

  final bool isNative;

  late LinkedList<Parameter> parameter; //参数列表

  late Block block; //函数主体

  late NativeFunctionProc proc; //内置函数

  //int count = 0; //内置函数的参数个数 -1表示参数不受限制

  FunctionDefinition(this.name, this.isNative);

  @override
  String toString() {
    return " Function:$name";
  }
}

enum StatementType {
  EXPRESSION_STATEMENT,
  CONST_STATEMENT,
  BLOCK_STATEMENT,
  IF_STATEMENT,
  WHILE_STATEMENT,
  FOR_STATEMENT,
  RETURN_STATEMENT,
  BREAK_STATEMENT,
  CONTINUE_STATEMENT,
  SWITCH_STATEMENT,
  TRY_STATEMENT,
  STATEMENT_TYPE_COUNT_PLUS_1
}

class IdentifierList extends LinkedListEntry<IdentifierList> {
  final Expression expression;
  IdentifierList(this.expression);
}

class BlockStatement {
  final Block block;
  const BlockStatement(this.block);
}

class ReturnStatement {
  final Expression returnvalue;
  const ReturnStatement(this.returnvalue);
}

class ConstStatement {
  final LinkedList<IdentifierList> identifierList;
  const ConstStatement(this.identifierList);
}

class Elsif extends LinkedListEntry<Elsif> {
  final Expression condition;
  final Block block;
  Elsif(this.condition, this.block);
}

class IfStatement {
  final Expression condition;
  final Block thenblock;
  LinkedList<Elsif> elsifList = LinkedList();
  Block elseblock = Block()..statementList = LinkedList();
  IfStatement(this.condition, this.thenblock);
}

class WhileStatement {
  final Expression condition;
  final Block block;
  const WhileStatement(this.condition, this.block);
}

class CaseList extends LinkedListEntry<CaseList> {
  final LinkedList<Expression> expressionList;
  final Block block;
  CaseList(this.expressionList, this.block);
}

class TryStatement {
  final Block tryblock;
  final Block catchblock;
  final String exception;
  late Block finallyblock;
  TryStatement(this.tryblock, this.catchblock, this.exception);
}

class SwitchStatement {
  final Expression expression;
  final LinkedList<CaseList> caseList;
  late Block defaultblock;
  SwitchStatement(this.expression, this.caseList);
}

class ForStatement {
  late Expression init;
  late Expression condition;
  late Expression post;
  final Block block;
  ForStatement(this.block);
}

///语句定义
class Statement extends LinkedListEntry<Statement> {
  late StatementType type;
  late BlockStatement blocks;
  late Expression expressions;
  late ReturnStatement returns;
  late ConstStatement consts;
  late IfStatement ifs;
  late WhileStatement whiles;
  late TryStatement trys;
  late SwitchStatement switchs;
  late ForStatement fors;
  Statement();
}

enum StatementResultType {
  NORMAL_STATEMENT_RESULT,
  RETURN_STATEMENT_RESULT,
  BREAK_STATEMENT_RESULT,
  CONTINUE_STATEMENT_RESULT,
  ERROR_RUNTIME_RESULT,
  STATEMENT_RESULT_TYPE_COUNT_PLUS_1
}

class StatementResult {
  StatementResultType type;
  Value returnvalue = Value(ValueType.NULL_VALUE, null);
  String? error;
  StatementResult({this.type = StatementResultType.NORMAL_STATEMENT_RESULT});
  @override
  String toString() {
    if (type == StatementResultType.ERROR_RUNTIME_RESULT) {
      return error!;
    } else {
      return "$type:$returnvalue";
    }
  }
}

//复数类
class Complex {
  num a;
  num b;
  Complex(this.a, this.b);

  num getModulo() {
    return sqrt(NumUtil.add(pow(a, 2), pow(b, 2)));
  }

  @override
  String toString() {
    if (a == 0) {
      return "${b.toString()}i";
    } else {
      return b > 0
          ? "${a.toString()} + ${b.toString()}i"
          : "${a.toString() + b.toString()}i";
    }
  }

  @override
  bool operator ==(Object other) {
    if ((other is Complex) && (a == other.a) && (b == other.b)) {
      return true;
    }
    return false;
  }

  @override
  int get hashCode => Object.hash(a, b);

  operator +(Object other) {
    if (other is num) {
      return Complex(a + other, b);
    } else if (other is Complex) {
      a += other.a;
      b += other.b;

      return Complex(a, b);
    }
  }

  operator -(Object other) {
    if (other is num) {
      return Complex(a - other, b);
    } else if (other is Complex) {
      a -= other.a;
      b -= other.b;

      return Complex(a, b);
    }
  }

  bool operator >(Object other) {
    if (other is num) {
      var t1 = NumUtil.multiply(a, a) + NumUtil.multiply(b, b);
      return t1 > NumUtil.multiply(other, other);
    } else {
      var t1 = NumUtil.multiply(a, a) + NumUtil.multiply(b, b);
      other as Complex;
      var t2 = NumUtil.multiply(other.a, other.a) +
          NumUtil.multiply(other.b, other.b);
      return t1 > t2;
    }
  }

  bool operator >=(Object other) {
    if (other is num) {
      var t1 = NumUtil.multiply(a, a) + NumUtil.multiply(b, b);
      return t1 >= NumUtil.multiply(other, other);
    } else {
      var t1 = NumUtil.multiply(a, a) + NumUtil.multiply(b, b);
      other as Complex;
      var t2 = NumUtil.multiply(other.a, other.a) +
          NumUtil.multiply(other.b, other.b);
      return t1 >= t2;
    }
  }

  bool operator <(Object other) {
    if (other is num) {
      var t1 = NumUtil.multiply(a, a) + NumUtil.multiply(b, b);
      return t1 < NumUtil.multiply(other, other);
    } else {
      var t1 = NumUtil.multiply(a, a) + NumUtil.multiply(b, b);
      other as Complex;
      var t2 = NumUtil.multiply(other.a, other.a) +
          NumUtil.multiply(other.b, other.b);
      return t1 < t2;
    }
  }

  bool operator <=(Object other) {
    if (other is num) {
      var t1 = NumUtil.multiply(a, a) + NumUtil.multiply(b, b);
      return t1 <= NumUtil.multiply(other, other);
    } else {
      var t1 = NumUtil.multiply(a, a) + NumUtil.multiply(b, b);
      other as Complex;
      var t2 = NumUtil.multiply(other.a, other.a) +
          NumUtil.multiply(other.b, other.b);
      return t1 <= t2;
    }
  }
}

///矩阵类型
enum MatrixType {
  ///一般矩阵
  GeneralMatrix,
  RealMatrix,
  ComplexMatrix,
}

///数组类
class ArrayValue {
  List<List<Value>> array = List.empty(growable: true);
  ArrayValue();
  int get length => array.length;
  get type => isReal();

  int llength(int h) {
    if (h >= length) return 0;

    return array.elementAt(h).length;
  }

  ///矩阵类型
  ///
  /// [RealMatrix]和[ComplexMatrix]都是可矩阵计算的类型
  /// 必须是m*n形的
  ///
  MatrixType isReal() {
    int? l;
    MatrixType? type;
    for (var element in array) {
      l ??= element.length;
      if (l != element.length) return MatrixType.GeneralMatrix;
      if (type == null) {
        for (var entry in element) {
          if (entry.type != ValueType.INT_VALUE &&
              entry.type != ValueType.DOUBLE_VALUE &&
              entry.type != ValueType.COMPLEX_VALUE) {
            return MatrixType.GeneralMatrix;
          }
          if (entry.type == ValueType.COMPLEX_VALUE) {
            type = MatrixType.ComplexMatrix;
          }
        }
      }
    }

    return type ?? MatrixType.RealMatrix;
  }

  bool isdeterminant() {
    int i = length;
    for (var element in array) {
      if (element.length != i) return false;
    }
    return true;
  }

  Value getValue(int h, {int l = 0}) {
    if (h >= length) return Value(ValueType.NULL_VALUE, null);
    if (l >= llength(h)) return Value(ValueType.NULL_VALUE, null);
    return array.elementAt(h).elementAt(l);
  }

  void setValue(int h, Value value, {int l = 0}) {
    if (h >= length) return;
    if (l >= llength(h)) return;

    int t1 = 0;
    Value? v;
    for (var entry in array[h]) {
      if (t1 == l) {
        v = entry;
      }
      t1++;
    }
    if (v != null) {
      v.insertBefore(value);
      array[h].remove(v);
    }
  }

  @override
  String toString() {
    if (array.isEmpty) {
      return "[]";
    } else {
      String t1 = "[";
      for (var e in array) {
        for (var entry in e) {
          t1 += "$entry,";
        }
        t1 += ";";
      }
      t1 += "]";
      t1 = t1.replaceAll(",;", ";");
      t1 = t1.replaceAll(";]", "]");
      return t1;
    }
  }

  @override
  bool operator ==(Object other) {
    if (other is ArrayValue) {
      if (array.isEmpty) {
        return other.array.isEmpty;
      } else {
        if (array.length != other.array.length) return false;

        for (var j = 0; j < array.length; j++) {
          for (Value? i = array[j].first, f = other.array[j].first;
              (i != null) && (f != null);
              i = i.next, f = f.next) {
            if ((i.type != f.type) || (i.value != f.value)) {
              return false;
            }
          }
        }
        return true;
      }
    }
    return false;
  }

  @override
  int get hashCode => Object.hash(array, length);

  ///是否同形
  bool isSameOrder(ArrayValue value) {
    if (length != value.length) return false;
    int i = 0;
    for (i; i < length; i++) {
      if (array[i].length != value.array[i].length) {
        return false;
      }
    }
    return true;
  }

  operator +(ArrayValue value) {
    if (isSameOrder(value)) {
      ArrayValue t2 = ArrayValue();
      StatementResult result;
      for (int i = 0; i < length; i++) {
        List<Value> t3 = List.empty(growable: true);
        Value? t1 = value.array[i].first;
        for (var entry in array[i]) {
          result = binaryExpression(entry, t1!, ExpressionType.ADD_EXPRESSION);
          if (result.type == StatementResultType.ERROR_RUNTIME_RESULT) {
            return Value(ValueType.NULL_VALUE, null);
          }
          t3.add(result.returnvalue);
          t1 = t1.next;
        }
        t2.array.add(t3);
      }
      return Value(ValueType.ARRAY_VALUE, t2);
    } else {
      return Value(ValueType.NULL_VALUE, null);
    }
  }

  operator -(ArrayValue value) {
    if (isSameOrder(value)) {
      ArrayValue t2 = ArrayValue();
      StatementResult result;
      for (int i = 0; i < length; i++) {
        List<Value> t3 = List.empty(growable: true);
        Value? t1 = value.array[i].first;
        for (var entry in array[i]) {
          result = binaryExpression(entry, t1!, ExpressionType.SUB_EXPRESSION);
          if (result.type == StatementResultType.ERROR_RUNTIME_RESULT) {
            return Value(ValueType.NULL_VALUE, null);
          }
          t3.add(result.returnvalue);
          t1 = t1.next;
        }
        t2.array.add(t3);
      }
      return Value(ValueType.ARRAY_VALUE, t2);
    } else {
      return Value(ValueType.NULL_VALUE, null);
    }
  }

  operator *(ArrayValue value) {
    if (isSameOrder(value)) {
      ArrayValue t2 = ArrayValue();
      StatementResult result;
      for (int i = 0; i < length; i++) {
        List<Value> t3 = List.empty(growable: true);
        Value? t1 = value.array[i].first;
        for (var entry in array[i]) {
          result = binaryExpression(entry, t1!, ExpressionType.MUL_EXPRESSION);
          if (result.type == StatementResultType.ERROR_RUNTIME_RESULT) {
            return Value(ValueType.NULL_VALUE, null);
          }
          t3.add(result.returnvalue);
          t1 = t1.next;
        }
        t2.array.add(t3);
      }
      return Value(ValueType.ARRAY_VALUE, t2);
    } else {
      return Value(ValueType.NULL_VALUE, null);
    }
  }

  operator /(ArrayValue value) {
    if (isSameOrder(value)) {
      ArrayValue t2 = ArrayValue();
      StatementResult result;
      for (int i = 0; i < length; i++) {
        List<Value> t3 = List.empty(growable: true);
        Value? t1 = value.array[i].first;
        for (var entry in array[i]) {
          result = binaryExpression(entry, t1!, ExpressionType.DIV_EXPRESSION);
          if (result.type == StatementResultType.ERROR_RUNTIME_RESULT) {
            return Value(ValueType.NULL_VALUE, null);
          }
          t3.add(result.returnvalue);
          t1 = t1.next;
        }
        t2.array.add(t3);
      }
      return Value(ValueType.ARRAY_VALUE, t2);
    } else {
      return Value(ValueType.NULL_VALUE, null);
    }
  }

  operator &(ArrayValue value) {
    if (isSameOrder(value)) {
      ArrayValue t2 = ArrayValue();
      StatementResult result;
      for (int i = 0; i < length; i++) {
        List<Value> t3 = List.empty(growable: true);
        Value? t1 = value.array[i].first;
        for (var entry in array[i]) {
          result =
              binaryExpression(entry, t1!, ExpressionType.BIT_AND_EXPRESSION);
          if (result.type == StatementResultType.ERROR_RUNTIME_RESULT) {
            return Value(ValueType.NULL_VALUE, null);
          }
          t3.add(result.returnvalue);
          t1 = t1.next;
        }
        t2.array.add(t3);
      }
      return Value(ValueType.ARRAY_VALUE, t2);
    } else {
      return Value(ValueType.NULL_VALUE, null);
    }
  }

  operator |(ArrayValue value) {
    if (isSameOrder(value)) {
      ArrayValue t2 = ArrayValue();
      StatementResult result;
      for (int i = 0; i < length; i++) {
        List<Value> t3 = List.empty(growable: true);
        Value? t1 = value.array[i].first;
        for (var entry in array[i]) {
          result =
              binaryExpression(entry, t1!, ExpressionType.BIT_OR_EXPRESSION);
          if (result.type == StatementResultType.ERROR_RUNTIME_RESULT) {
            return Value(ValueType.NULL_VALUE, null);
          }
          t3.add(result.returnvalue);
          t1 = t1.next;
        }
        t2.array.add(t3);
      }
      return Value(ValueType.ARRAY_VALUE, t2);
    } else {
      return Value(ValueType.NULL_VALUE, null);
    }
  }

  operator ^(ArrayValue value) {
    if (isSameOrder(value)) {
      ArrayValue t2 = ArrayValue();
      StatementResult result;
      for (int i = 0; i < length; i++) {
        List<Value> t3 = List.empty(growable: true);
        Value? t1 = value.array[i].first;
        for (var entry in array[i]) {
          result =
              binaryExpression(entry, t1!, ExpressionType.BIT_XOR_EXPRESSION);
          if (result.type == StatementResultType.ERROR_RUNTIME_RESULT) {
            return Value(ValueType.NULL_VALUE, null);
          }
          t3.add(result.returnvalue);
          t1 = t1.next;
        }
        t2.array.add(t3);
      }
      return Value(ValueType.ARRAY_VALUE, t2);
    } else {
      return Value(ValueType.NULL_VALUE, null);
    }
  }

  operator %(ArrayValue value) {
    if (isSameOrder(value)) {
      ArrayValue t2 = ArrayValue();
      StatementResult result;
      for (int i = 0; i < length; i++) {
        List<Value> t3 = List.empty(growable: true);
        Value? t1 = value.array[i].first;
        for (var entry in array[i]) {
          result = binaryExpression(entry, t1!, ExpressionType.MOD_EXPRESSION);
          if (result.type == StatementResultType.ERROR_RUNTIME_RESULT) {
            return Value(ValueType.NULL_VALUE, null);
          }
          t3.add(result.returnvalue);
          t1 = t1.next;
        }
        t2.array.add(t3);
      }
      return Value(ValueType.ARRAY_VALUE, t2);
    } else {
      return Value(ValueType.NULL_VALUE, null);
    }
  }

  operator >(ArrayValue value) {
    if (isSameOrder(value)) {
      ArrayValue t2 = ArrayValue();
      StatementResult result;
      for (int i = 0; i < length; i++) {
        List<Value> t3 = List.empty(growable: true);
        Value? t1 = value.array[i].first;
        for (var entry in array[i]) {
          result = binaryExpression(entry, t1!, ExpressionType.GT_EXPRESSION);
          if (result.type == StatementResultType.ERROR_RUNTIME_RESULT) {
            return Value(ValueType.NULL_VALUE, null);
          }
          t3.add(result.returnvalue);
          t1 = t1.next;
        }
        t2.array.add(t3);
      }
      return Value(ValueType.ARRAY_VALUE, t2);
    } else {
      return Value(ValueType.NULL_VALUE, null);
    }
  }

  operator >=(ArrayValue value) {
    if (isSameOrder(value)) {
      ArrayValue t2 = ArrayValue();
      StatementResult result;
      for (int i = 0; i < length; i++) {
        List<Value> t3 = List.empty(growable: true);
        Value? t1 = value.array[i].first;
        for (var entry in array[i]) {
          result = binaryExpression(entry, t1!, ExpressionType.GE_EXPRESSION);
          if (result.type == StatementResultType.ERROR_RUNTIME_RESULT) {
            return Value(ValueType.NULL_VALUE, null);
          }
          t3.add(result.returnvalue);
          t1 = t1.next;
        }
        t2.array.add(t3);
      }
      return Value(ValueType.ARRAY_VALUE, t2);
    } else {
      return Value(ValueType.NULL_VALUE, null);
    }
  }

  operator <(ArrayValue value) {
    if (isSameOrder(value)) {
      ArrayValue t2 = ArrayValue();
      StatementResult result;
      for (int i = 0; i < length; i++) {
        List<Value> t3 = List.empty(growable: true);
        Value? t1 = value.array[i].first;
        for (var entry in array[i]) {
          result = binaryExpression(entry, t1!, ExpressionType.LT_EXPRESSION);
          if (result.type == StatementResultType.ERROR_RUNTIME_RESULT) {
            return Value(ValueType.NULL_VALUE, null);
          }
          t3.add(result.returnvalue);
          t1 = t1.next;
        }
        t2.array.add(t3);
      }
      return Value(ValueType.ARRAY_VALUE, t2);
    } else {
      return Value(ValueType.NULL_VALUE, null);
    }
  }

  operator <=(ArrayValue value) {
    if (isSameOrder(value)) {
      ArrayValue t2 = ArrayValue();
      StatementResult result;
      for (int i = 0; i < length; i++) {
        List<Value> t3 = List.empty(growable: true);
        Value? t1 = value.array[i].first;
        for (var entry in array[i]) {
          result = binaryExpression(entry, t1!, ExpressionType.LE_EXPRESSION);
          if (result.type == StatementResultType.ERROR_RUNTIME_RESULT) {
            return Value(ValueType.NULL_VALUE, null);
          }
          t3.add(result.returnvalue);
          t1 = t1.next;
        }
        t2.array.add(t3);
      }
      return Value(ValueType.ARRAY_VALUE, t2);
    } else {
      return Value(ValueType.NULL_VALUE, null);
    }
  }
}
